# Common data for user-interface componnets: uimain, led, ped
#
# Copyright (C) 2010 Yotam Medini <yotam.medini@gmail.com>
#
# This file is part of Gupicasa.
#
# Gupicasa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Gupicasa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gupicasa.  If not, see <http://www.gnu.org/licenses/>.


import gtk
import os.path
import sys

import debug
import pref
import ugtk


class Common:


    def __init__(self, topwin=None, warner=None):
        self.preferences = pref.Preferences()
        self.register_stock_icons()
        self.statusbar = ugtk.SimpleStatusbar()
        self.topwin = topwin
        if warner is None:
            warner = (lambda t: sys.stderr.write("common-Warning: %s\n" % t))
        self.warner = warner


    def register_stock_icons(self):
        # Add our custom icon factory to the list of defaults
        factory = gtk.IconFactory()
        factory.add_default()

        img_dir = os.path.join(os.path.dirname(__file__), 'images')
        # http://picasa.google.com/logo_smaller.gif
        self.icons_pixbuf = {}
        for name in ("picasa-logo", "gupicasa"):
            img_path = os.path.join(img_dir, name + '.jpeg')
            pixbuf = gtk.gdk.pixbuf_new_from_file(img_path)
            self.icons_pixbuf[name] = pixbuf
            transparent = pixbuf.add_alpha(True, chr(255), chr(255),chr(255))
            icon_set = gtk.IconSet(transparent)
            factory.add(name, icon_set)


    def warning(self, msg):
        self.warner(msg)

